<!DOCTYPE html>
<html>
<head>
  <title></title>
  <script src="../resources/jquery.js"></script>
  <link rel="stylesheet" href="css/common.css">
  <link rel="stylesheet" href="css/menu.css">
  <link rel="stylesheet" href="css/users.css">
</head>
<body>
<?php
/**
 * Created by PhpStorm.
 * User: Aliaxander Lazerka
 * Date: 10/26/14
 * Time: 5:45 AM
 */
include_once("loginCheck.php");
include_once("elems/menu.php");
?>

<script>
  $('#directoryDiv').html('Действия с пользователями')
</script>
<div class="bodyDiv">
  <?php
  include_once("functions/db_manipulate.php");
  $users = getAllUsers();
  ?>

  <table class="userTable">
    <tr>
      <td>
        Логин
      </td>
      <td>
        Имя
      </td>
      <td>
        Фамилия
      </td>
      <td>
        Email
      </td>
      <td>
        Телефон
      </td>
      <td>
        Роль
      </td>
      <td>
        Действия
      </td>
    </tr>

    <?php while ($user = mysql_fetch_assoc($users)) {
      $roles = getAllRoles();
      ?>
      <tr>
        <td>
          <?= $user['USERNAME'] ?>
        </td>
        <td>
          <?= $user['FIRST_NAME'] ?>
        </td>
        <td>
          <?= $user['LAST_NAME'] ?>
        </td>
        <td>
          <?= $user['EMAIL'] ?>
        </td>
        <td>
          <?= $user['MOBILE'] ?>
        </td>
        <td>
          <form method="post" action="?eUH&act=edit" id="editUserForm">
            <select name="usrRole">
              <?php
              while ($role = mysql_fetch_array($roles)) {
                if ($user['ROLE'] == $role['ROLE']) {
                  ?>
                  <option selected value="<?= $role['ID']; ?>"><?= $role['ROLE']; ?></option>
                <?php
                } else {
                  ?>
                  <option value="<?= $role['ID']; ?>"><?= $role['ROLE']; ?></option>
                <?php
                }
              }
              ?>
            </select>
            <input type="hidden" name="usrId" value="<?= $user['ID'] ?>">
          </form>
        </td>
        <td>
          <acronym title="Изменить роль пользователя">
            <img src="../img/check_16.png" onclick="$('#editUserForm').submit()">
          </acronym>
          <acronym title="Отправить пользователю сообщение">
            <img src="../img/mail_16.png">
          </acronym>
          <acronym title="Удалить пользователя">
            <img src="../img/close_16.png" onclick="location.href='?eUH&act=del&uid=<?= $user['ID'] ?>'">
          </acronym>
        </td>
      </tr>
    <?php
    }
    ?>
  </table>
</div>
</body>